package com.ushio.gougouwangguo.service.impl;

import com.ushio.commonmodule.utils.JwtUtil;
import com.ushio.gougouwangguo.entity.mysql.ActionConfig;
import com.ushio.gougouwangguo.entity.mysql.UserTaskCell;
import com.ushio.gougouwangguo.entity.vo.ActionConfigVo;
import com.ushio.gougouwangguo.entity.vo.UserTaskCellVo;
import com.ushio.gougouwangguo.entity.vo.UserTaskTypeVo;
import com.ushio.gougouwangguo.mapper.ActionConfigMapper;
import com.ushio.gougouwangguo.mapper.UserTaskCellMapper;
import com.ushio.gougouwangguo.service.IUserTaskCellService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 任务单元格 服务实现类
 * </p>
 *
 * @author 张文凯
 * @since 2025-10-26
 */
@Service
public class UserTaskCellServiceImpl extends ServiceImpl<UserTaskCellMapper, UserTaskCell> implements IUserTaskCellService {

    @Autowired
    UserTaskCellMapper userTaskCellMapper;
    @Autowired
    ActionConfigMapper actionConfigMapper;
    @Override
    @Transactional
    public List<UserTaskCellVo> getUserTaskCellArchitecture() {
        return getUserTaskCellUtils(1);
    }

    @Override
    public List<UserTaskCellVo> getUserTaskCellForest() {
        return getUserTaskCellUtils(2);
    }

    public List<UserTaskCellVo> getUserTaskCellUtils(Integer actionConfigTypeId){
        Long userId = JwtUtil.parseUser().getUserId();

        List<UserTaskCellVo> userTaskCellVos =  userTaskCellMapper.getUserTaskCell(userId,actionConfigTypeId);

        List<ActionConfigVo> actionConfigAll = actionConfigMapper.getActionConfigAll();

        for (UserTaskCellVo userTaskCellVo:userTaskCellVos) {

            List<ActionConfigVo> actionConfigVoList = new ArrayList<>();

            for (ActionConfigVo actionConfigVo :actionConfigAll) {

                if (userTaskCellVo.getActionConfigId().equals(actionConfigVo.getActionConfigId())){

                    actionConfigVoList.add(actionConfigVo);

                }

            }
            userTaskCellVo.setActionConfigVoList(actionConfigVoList);
        }
        return userTaskCellVos;
    }
}
